10 ' reverse_.bas - FreeWare 2005 - eric f. tchong
20 GOTO 90 ' begin
30 SAVE"reverse_",A:LIST-90
40 GOTO 600 ' print digits
50 GOTO 660 ' get key input
60 GOTO 700 ' print random digits
70 GOTO 1150 ' show arrow
80 ' begin
90 CLS:COLOR 15,1:KEY OFF:RANDOMIZE TIMER
100 DEFINT A-Z:DEFSTR Q:Q=MKI$(0):READ N:DIM P$(N),C(7)
110 FOR I=1 TO 7:READ C(I):NEXT ' C(I) 28 219 29 31 223 220 32
120 ' assemble digits
130 FOR H=1 TO N
140  READ K$
150  FOR G=1 TO LEN(K$):P$(H)=P$(H)+CHR$(C(VAL(MID$(K$,G,1)))):NEXT
160 NEXT
170 PRINT "This is the game of REVERSE"
180 PRINT "     by Eric F. Tchong     "
190 PRINT "       FreeWare 2005       "
200 PRINT "                           "
210 PRINT "  Press <y/Y> for a demo   "
220 GOSUB 50:IF E=27 THEN 750
230 IF E=89 OR E=121 THEN 770
240 ' Make a random list
250 A(1)=INT(RND*9)+1
260 FOR K=2 TO 9
270  A(K)=INT(RND*9)+1
280   FOR J=1 TO K-1
290    IF A(K)=A(J) THEN F=1
300   NEXT
310  IF F=1 THEN F=0:GOTO 270
320 NEXT
330 ' Game starts here
340 CLS:COLOR 14,1
350 LOCATE 1,1 :PRINT STRING$(80,219);:LOCATE 25,1:PRINT STRING$(80,219);
360 COLOR 12,1:V=4:R=9
370 FOR N=1 TO R                       ' print digits
380  F=1+9*(N-1):U=N:GOSUB 40
390 NEXT
400 GOSUB 60                           ' print random digits
410 LOCATE 12,2:PRINT "Reverse how many? "
420 LOCATE 23,2:PRINT "Esc = Stop";
430 GOSUB 50:IF E=27 THEN 750
440 IF R<1 OR R>9 THEN 410
450 LOCATE 12,21:PRINT R:T=T+1
460 ' Reverse and check for a win
470 FOR K=1 TO INT(R/2)                ' 5 2 3 4 1 6 7 8 9
480  Z=A(K):A(K)=A(R-K+1):A(R-K+1)=Z   ' 1 4 3 2 5 6 7 8 9
490 NEXT
500 FOR K=1 TO 9
510  IF A(K)<>K THEN F=1
520 NEXT:IF F=1 THEN 400
530 ' Yes there is a win
540 GOSUB 60
550 LOCATE 12,2:PRINT "Solved in";T;"steps...  ":BEEP
560 LOCATE 13,2:PRINT "Once again  <y/n> ?"
570 GOSUB 50:IF E=110 OR E=78 OR E=27 THEN 750
580 T=0:GOTO 250
590 ' Print digits
600 FOR P=1 TO 7                       ' 7 was 5
610  LOCATE V+P-1,F
620  PRINT MID$(P$(U),(P-1)*8+1,8)     ' 8 was 5
630 NEXT
640 RETURN
650 ' Get key input
660 LSET Q=MKI$(0)
670 WHILE CVI(Q)=0:MID$(Q,1)=INKEY$:WEND
680 R=VAL(Q):E=ASC(Q):RETURN
690 ' Print random digits
700 V=15:COLOR 11,1
710 FOR N=1 TO R
720  F=1+9*(N-1):U=A(N):GOSUB 40       ' 1+9* was 2+9*
730 NEXT:COLOR 15,1:RETURN
740 ' Exit
750 COLOR 7,0:CLS:END
760 ' demo
770 CLS:COLOR 14,1
780 LOCATE 1,1:PRINT STRING$(80,219);:LOCATE 25,1:PRINT STRING$(80,219);
790 LOCATE 4,2:COLOR 12,1
800 PRINT "The game of REVERSE requires you"
810 PRINT " to arrange a list of numbers in"
820 PRINT " numerical order from left to right!"
830 PRINT " To move, you tell the computer"
840 PRINT " how many numbers (counting from"
850 PRINT " the left) to reverse.":PRINT:COLOR 11,1
860 PRINT " The current list is: 2 3 4 5 1 6 7 8 9":COLOR 15,1
870 A(1)=2:A(2)=3:A(3)=4:A(4)=5:A(5)=1:A(6)=6:A(7)=7:A(8)=8:A(9)=9
880 R=9:GOSUB 60
890 LOCATE 12,2:PRINT "Reverse how many? 4"
900 LOCATE 13,2:PRINT "Press 4":GOSUB 70:GOSUB 50
910 IF E=27 THEN 750
920 IF R<>4 THEN 900
930 FOR K=1 TO INT(R/2)                ' 2 3 4 5 1 6 7 8 9
940  Z=A(K):A(K)=A(R-K+1):A(R-K+1)=Z   ' 5 4 3 2 1 6 7 8 9
950 NEXT
960 GOSUB 60:COLOR 11,1
970 LOCATE 11,2:PRINT "The current list is: 5 4 3 2 1 6 7 8 9":COLOR 15,1
980 LOCATE 12,2:PRINT "Reverse how many? 5"
990 LOCATE 13,2:PRINT "Press 5":GOSUB 70:GOSUB 50
1000 IF E=27 THEN 750
1010 IF R<>5 THEN 990
1020 FOR K=1 TO INT(R/2)                ' 2 3 4 5 1 6 7 8 9
1030  Z=A(K):A(K)=A(R-K+1):A(R-K+1)=Z   ' 1 2 3 4 5 6 7 8 9
1040 NEXT
1050 GOSUB 60:BEEP:COLOR 11,1
1060 LOCATE 11,2:PRINT "The current list is: 1 2 3 4 5 6 7 8 9":COLOR 15,1
1070 LOCATE 12,2:PRINT "A correct numerical order."
1080 LOCATE 13,2:PRINT "Repeat this demo? <y/Y>"
1090 GOSUB 50: IF E=89 OR E=121 THEN 770
1100 IF E=27 THEN 750
1110 SOUND 2000,1
1120 LOCATE 23,2:PRINT "ENJOY THIS GAME, GOOD LUCK - press a key to start"
1130 GOSUB 50:GOTO 250
1140 ' show arrow
1150 FOR Z=1 TO 12
1160  LOCATE 13,10:PRINT "      ":SOUND .49, .2
1170  LOCATE 13,10:PRINT "<-----":SOUND .49, .2
1180 NEXT:RETURN
1190 ' 9    1  2   3  4  5   6   7           TRS-80 dot matrix 7x8
1200 DATA 9,28,219,29,31,223,220,32
1210 '    12345678123456781234567812345678123456781234567812345678
1220 DATA 77222777722227777772277777722777777227777772277722222222 : '1
1230 DATA 72222227227777227777772277772277772277772277777722222222 : '2
1240 DATA 72222227227777227777772277222227777777222277772272222227 : '3
1250 DATA 77722227772272277227722722777227222222227777722777777227 : '4
1260 DATA 22222222227777772222222777777722777777222277772272222227 : '5
1270 DATA 72222227227777222277777722222227227777222277772272222227 : '6
1280 DATA 22222222777772277777227777722777772277777227777772277777 : '7
1290 DATA 72222227227777222277772272222227227777222277772272222227 : '8
1300 DATA 72222227227777222277772272222222777777222277772272222227 : '9
1310 REM  12345678123456781234567812345678123456781234567812345678
